#include <cstdio>
#include <cstring>

const int SIZE = 4;
const int DIRECTION = 8;
int N;
char A[SIZE][SIZE + 1];
char D[105][20];
int size_d;

void input() {
    for(int i = 0; i < SIZE; ++i) {
        scanf("%s", A[i]);
    }
    scanf("%d", &size_d);
    for(int i = 0; i < size_d; ++i) {
        scanf("%s", D[i]);
    }
}

/*
 *  7 0 1
 *  6 + 2
 *  5 4 3
 */
const int direct[DIRECTION][2] = {{-1, 0}, {-1,  1}, {0,  1}, { 1,  1}, 
                                  { 1, 0}, { 1, -1}, {0, -1}, {-1, -1}};

void traversal(int& r, int z, int y, int x, int b, int e, unsigned long long d) {
    if(b == e) {
        r = 1;
    } else if(r == 0) {
        if(y >= 0 && y < SIZE && x >= 0 && x < SIZE && A[y][x] == D[z][b]) {
            unsigned long long pos = y * SIZE + x;
            unsigned long long tmp = d;
            int q = 0;
            for(; q < b; ++q, tmp >>= 4) {
                if((tmp & 0xF) == pos) {
                    break;
                }
            }
            if(q == b) {
                for(int i = 0; i < DIRECTION; ++i) {
                    int next_y = y + direct[i][0];
                    int next_x = x + direct[i][1];
                    traversal(r, z, next_y, next_x, b + 1, e, d | pos << (b << 2));
                    if(r == 1) {
                        return;
                    }
                }
            }
        }
    }
}

int cal() {
    int score = 0;
    for(int i = 0; i < size_d; ++i) {
        for(int j = 0; j < SIZE; ++j) {
            for(int k = 0; k < SIZE; ++k) {
                if(A[j][k] == D[i][0]) {
                    int r = 0, len = strlen(D[i]);
                    traversal(r, i, j, k, 0, len, 0ULL);
                    if(r != 0) {
                        if(len >= 8) {
                            score += 11;
                        } else if(len == 7) {
                            score += 5;
                        } else if(len == 6) {
                            score += 3;
                        } else if(len == 5) {
                            score += 2;
                        } else if(len == 4) {
                            score += 1;
                        } else if(len == 3) {
                            score += 1;
                        }
                        goto SEARCH_END;
                    }
                }
            }
        }
SEARCH_END:
        ;
    }
    return score;
}

void output(int cases) {
    printf("Score for Boggle game #%d: %d\n", cases, cal());
}

int main() {
    scanf("%d", &N);
    for(int i = 1; i <= N; ++i) {
        input();
        output(i);
    }
    return 0;
}
